//: Playground - noun: a place where people can play

import UIKit
import Foundation

var str = "Hello, playground"

//:  ***创建自己的类型***
enum OCBool {
    case ocTrue
    case ocFalse
}

extension OCBool {
    init() {
        self = .ocFalse
    }
}

//: ***实现BooleanLiteralConvertible协议，可以使用Bool类型进行初始化***
extension OCBool:BooleanLiteralConvertible {
    init(booleanLiteral value: Bool) {
        self = value ? .ocTrue : .ocFalse
    }
}

//: ***实现BooleanType协议，可以将枚举数据进行Bool类型判断***
extension OCBool:BooleanType {
    var boolValue: Bool {
        if self == .ocFalse {
            return false
        }
        else if self == .ocTrue {
            return true
        }
        return true
    }
}

extension OCBool: Equatable {
}

//: ***==等于运算***
func ==(lhs: OCBool, rhs: OCBool) -> Bool {
    switch (lhs, rhs) {
    case (.ocTrue, .ocTrue):
        return true
    default:
        return false
    }
}

//: ***&与运算***
func &(lhs: OCBool, rhs: OCBool) -> OCBool {
    if lhs {
        return rhs
    }
    else {
        return false
    }
}

//: ***|或运算***
func | (lhs: OCBool, rhs: OCBool) -> OCBool {
    if lhs {
        return true
    }
    else {
        return rhs
    }
}

var result01:OCBool = OCBool()
var result02:OCBool = .ocTrue

var result03:OCBool = true
var result04:OCBool = false

if result03 {
    print("吃饭啦")
}

let isEqual01 = result03 == result02
let isEqual02 = result03 & result04
let isEqual03 = result03 | result04
